package com.ssh.util;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author manster
 * @Date 2022/3/13
 **/
@Data
public class R implements Serializable {

    private Integer code;

    private String msg;

    private Object data;

    //构造方法私有化
    private R(){}

    //成功方法
    public static R success(){
        R r = new R();
        r.setCode(200);
        r.setMsg("success");
        return r;
    }

    //失败方法
    public static R fail(){
        R r = new R();
        r.setCode(400);
        r.setMsg("fail");
        return r;
    }

    //链式调用
    public R msg(String msg){
        this.setMsg(msg);
        return this;
    }
    public R code(Integer code){
        this.setCode(code);
        return this;
    }
    public R data(Object obj){
        this.setData(obj);
        return this;
    }
}
